package videoExercises;

import java.util.*;

//某个班级80名学生，现在需要组成秋游活动，班长提供了四个景点依次是（A、B、C、D），每个学生只能选择一个景点，
//请统计出最终哪个景点想去的人数最多。
public class Test9 {
    public static void main(String[] args) {
        String[] arr = {"A", "B", "C", "D"};
        ArrayList<String> array = new ArrayList<>();
        Random r = new Random();
        for (int i = 0; i < 80; i++) {
            int index = r.nextInt(arr.length);
            array.add(arr[index]);
        }
        HashMap<String, Integer> m = new HashMap<>();
        for (String name : array) {
            if (m.containsKey(name)) {
                Integer y = m.get(name);
                y++;
                m.put(name, y);
            } else {
                m.put(name, 1);
            }
        }
        System.out.println(m);

        int max = 0;
        Set<Map.Entry<String, Integer>> entries = m.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            int count = entry.getValue();
            if (count > max) {
                max = count;
            }
        }
        System.out.println(max);

        for (Map.Entry<String, Integer> entry : entries) {
            int count = entry.getValue();
            String key = entry.getKey();
            if(count == max){
                System.out.println(""+key);
            }
        }
    }
}
